<?php

declare (strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Model;

use Carbon\Carbon;
use Hyperf\Database\Query\Builder;
class VerifyCode extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected ?string $table = 'verify_code';
    public function scopeActive($q)
    {
        /** @var Builder $q */
        return $q->where('expires', '>', date('Y-m-d H:i:s'));
    }
    /**
     * 存入验证码
     * @param $code
     * @param $mobile
     * @return $this
     */
    public function send($code, $mobile)
    {
        $this->mobile = $mobile;
        $this->code = $code;
        $this->expires = Carbon::parse(time())->addMinutes(10)->toDateTimeString();
        return $this;
    }
}